<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../../styles/common.css"/>
    <link rel="stylesheet" href="../../styles/page.css"/>
    <style>
        #cost-detail-app .notAdmin::after {
            border: 0 !important;

        }

        .search-btn {
            margin-left: 20px;
        }

        .tableBar {
            justify-content: flex-start !important;
        }

        .info-box {
            margin: -15px -44px 20px;
        }

        .info-box .item-box {
            display: flex;
            height: 20px;
            line-height: 20px;
            font-size: 14px;
            font-weight: 400;
            color: #666666;
            text-align: left;
            margin-bottom: 14px;
        }

        .info-box .item-box:last-child {
            margin-bottom: 0;
        }

        .info-box .item-box .label {
            width: 96px;
        }

        .info-box .item-box .des {
            flex: 1;
            color: #333333;
        }

        .el-range-input {
            width: 35% !important;

        }

        .el-date-editor .el-range__close-icon {
            width: 13% !important;
        }

        .el-date-editor .el-range-separator {
            width: 10% !important;
        }

        .el-dropdown {
            vertical-align: top;
        }

        .el-dropdown + .el-dropdown {
            margin-left: 15px;
        }

        .el-icon-arrow-down {
            font-size: 12px;
        }

        .bsType {
            margin-left: 20px;
        }

        .tableBox {
            text-align-last: center;
        }
    </style>
</head>
<body>
<div class="dashboard-container" id="cost-detail-app">
    <div class="container">
        <!-- 搜索栏 -->
        <div class="tableBar">
            <el-date-picker v-model="costTime"
                            clearable
                            value-format="yyyy-MM-dd HH:mm:ss"
                            type="datetimerange"
                            placeholder="选择日期"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :default-time="['00:00:00', '23:59:59']"
                            style="width: 340px;"
            ></el-date-picker>
            <template>
                <el-select v-model="value" placeholder="业务类型" class="bsType" @change="handleCommand">
                    <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </template>

            <el-button type="primary" class="search-btn" @click="init">查询</el-button>
        </div>
        <el-table
                :data="tableData"
                stripe
                class="tableBox"
        >
            <el-table-column
                    prop="memberName"
                    label="会员姓名"
            ></el-table-column>
            <el-table-column
                    prop="bsType"
                    label="业务类型"
                    :formatter="formatBsType"
            ></el-table-column>
            <el-table-column
                    prop="costAmount"
                    label="发生金额"
            ></el-table-column>
            <el-table-column
                    prop="balance"
                    label="余额"
            ></el-table-column>
            <el-table-column
                    prop="createTime"
                    label="操作时间"
            ></el-table-column>
            <el-table-column
                    prop="remark"
                    label="备注"
            ></el-table-column>

        </el-table>
        <el-pagination
                class="pageList"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="counts"
                :current-page.sync="page"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
        ></el-pagination>
    </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vueMax.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/costAndMember.js"></script>
<script src="../../js/index.js"></script>
<script>
    new Vue({
        el: '#cost-detail-app',
        data() {
            return {
                input: '',
                counts: 0,
                page: 1,
                pageSize: 10,
                tableData: [],
                id: '',
                bsType: '',
                beginTime: '',
                endTime: '',
                costTime: '',
                options: [{
                    value: '1',
                    label: '充值'
                }, {
                    value: '2',
                    label: '扣费'
                }],
                value: '',
            }
        },
        computed: {},
        created() {
            this.id = requestUrlParam('id')
            this.init()
            this.user = JSON.parse(localStorage.getItem('userInfo')).username
        },
        mounted() {
        },
        watch: {
            costTime(val) {
                if (val && val.length >= 2) {
                    this.beginTime = val[0]
                    this.endTime = val[1]
                } else {
                    this.beginTime = ''
                    this.endTime = ''
                }
            }
        },
        methods: {
            async init() {
                const params = {
                    page: this.page,
                    pageSize: this.pageSize,
                    phone: this.id,
                    bsType: this.bsType,
                    beginTime: this.beginTime,
                    endTime: this.endTime,
                }
                await getCostRecordList(params).then(res => {
                    if (String(res.code) === '1') {
                        this.tableData = res.data.records || []
                        this.counts = res.data.total
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            handleQuery() {
                this.page = 1;
                this.init();
            },
            handleSizeChange(val) {
                this.pageSize = val
                this.init()
            },
            handleCurrentChange(val) {
                this.page = val
                this.init()
            },
            // 业务类型处理
            formatBsType(row, column, type, index) {
                switch (type) {
                    case 1:
                        return "充值";
                    case 2:
                        return "扣费";
                }
            },
            // 业务选择
            handleCommand(value) {
                switch (value) {
                    case "1": // 充值
                        this.bsType = 1
                        this.init()
                        break;
                    case "2": // 扣费
                        this.bsType = 2
                        this.init()
                        break;
                }
            }
        }
    })
</script>
</body>
</html>
